<template>
<div class="student_exam_paper_read">

  <el-container  class="app-item-contain">
    <div class="app-item-contain_l">
      <div>试卷名称:{{form.name}}</div>
      <p class="question-title">试卷得分：{{answer.score}}</p>
      <p class="question-title">试卷耗时：{{formatSeconds(answer.doTime)}}</p>
      <el-row  class="do-exam-title">
        <el-col :span="24">
        <span :key="item.itemOrder"  v-for="item in answer.answerItems">
             <el-tag :type="questionDoRightTag(item.doRight)" class="do-exam-title-tag" @click="goAnchor('#question-'+item.itemOrder)">{{item.itemOrder}}</el-tag>
        </span>
        </el-col>
      </el-row>
    </div>
    <div class="app-item-contain_r">
      <el-form :model="form" ref="form" v-loading="formLoading" label-width="100px">
        <el-row :key="index"  v-for="(titleItem,index) in form.titleItems">
          <h3>{{titleItem.name}}</h3>
          <div class="exampaper-item-box" v-if="titleItem.questionItems.length!==0">
            <el-form-item :key="questionItem.itemOrder" :label="questionItem.itemOrder+'.'"
                          v-for="questionItem in titleItem.questionItems"
                          class="exam-question-item"  label-width="50px" :id="'question-'+ questionItem.itemOrder">
              <QuestionAnswerShow :qType="questionItem.questionType" :question="questionItem"  :answer="answer.answerItems[questionItem.itemOrder-1]"/>
            </el-form-item>
          </div>
        </el-row>
      </el-form>
    </div>
  </el-container>
</div>
</template>

<script>
import { formatSeconds } from '@/utils'
import QuestionAnswerShow from '../components/QuestionAnswerShow'
import { read } from '@/api/examPaperAnswer'

export default {
  components: { QuestionAnswerShow },
  data () {
    return {
      form: {},
      formLoading: false,
      answer: {
        id: null,
        score: 0,
        doTime: 0,
        answerItems: [],
        doRight: false
      }
    }
  },
  created () {
    let id = this.$route.query.id
    let _this = this
    if (id && parseInt(id) !== 0) {
      _this.formLoading = true
      read(id).then(re => {
        _this.form = re.data.paper
        _this.answer = re.data.answer
        _this.formLoading = false
      })
    }
  },
  methods: {
    formatSeconds (theTime) {
      return formatSeconds(theTime)
    },
    questionDoRightTag(status) {
      if (status == null) {
        return 'warning'
      }
      if (status == true) {
        return 'success'
      }
      if (status == false) {
        return 'danger'
      }
    },
    goAnchor (selector) {
      this.$el.querySelector(selector).scrollIntoView({ behavior: 'instant', block: 'center', inline: 'nearest' })
    }
  },
  computed: {
    //...mapGetters('enumItem', ['enumFormat']),
   // ...mapState('enumItem', {
    //  doRightTag: state => state.exam.question.answer.doRightTag
    //})
  }
}
</script>

<style lang="scss" scoped>
  .align-center {
    text-align: center
  }

  .exam-question-item{
    padding: 10px;
    .el-form-item__label{
      font-size: 15px !important;
    }
  }

  .question-title-padding{
    padding-left: 25px;
    padding-right: 25px;
  }
</style>
